package com.example.myapplication51;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        FragmentManager fragmentManager=getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.fragment,new AFragment());
        transaction.commit();
        TextView v1=findViewById(R.id.index);
        TextView v2=findViewById(R.id.section);
        TextView v3=findViewById(R.id.ques);
        Button one=findViewById(R.id.one);
        Button two=findViewById(R.id.two);
        Button three=findViewById(R.id.three);
        one.setVisibility(View.VISIBLE);
        two.setVisibility(View.INVISIBLE);
        three.setVisibility(View.INVISIBLE);
        v1.setOnClickListener(this);
        v2.setOnClickListener(this);
        v3.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        AFragment aFragment=new AFragment();
        BFragment bFragment=new BFragment();
        CFragment cFragment=new CFragment();
        Button one=findViewById(R.id.one);
        Button two=findViewById(R.id.two);
        Button three=findViewById(R.id.three);
        switch (v.getId())
        {
            case R.id.index:
                replaceFragement(aFragment);
                one.setVisibility(View.VISIBLE);
                two.setVisibility(View.INVISIBLE);
                three.setVisibility(View.INVISIBLE);
                break;
            case R.id.section:
                replaceFragement(bFragment);
                two.setVisibility(View.VISIBLE);
                one.setVisibility(View.INVISIBLE);
                three.setVisibility(View.INVISIBLE);
                break;
            case R.id.ques:
                replaceFragement(cFragment);
                three.setVisibility(View.VISIBLE);
                two.setVisibility(View.INVISIBLE);
                one.setVisibility(View.INVISIBLE);
                break;
        }
    }

    private void replaceFragement(Fragment fragment) {
        FragmentManager fragmentManager=getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.fragment,fragment);
        transaction.commit();
    }
}